package my.sample.nio.channel;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;

public class SelectorTimeoutRead {

	/**
	 * @param args
	 */
	// private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(SelectorTimeoutRead.class);
	public static void main(String[] args) {
		
		InetSocketAddress ipAddress = null;
		DatagramChannel channel = null;
		ByteBuffer headerBuffer = ByteBuffer.allocate(args[2].length() + 1);

		try {
			ipAddress = new InetSocketAddress(InetAddress.getByName(args[0]), Integer.parseInt(args[1]));
		} catch (NumberFormatException e1) {
			e1.printStackTrace();
		} catch (UnknownHostException e1) {
			e1.printStackTrace();
		}
		
		
		
		
		try {
			channel = DatagramChannel.open();
			channel.connect(ipAddress);
			channel.socket().setSendBufferSize(131071);
//			System.out.println("connection status : " + channel.isConnected());
//			System.out.println("open status : " + channel.isOpen());
		} catch (IOException e) {
			try {
				channel.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}


		

	}
}
